package com.wedu.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wedu.common.utils.PageUtils;
import com.wedu.common.utils.Query;
import com.wedu.modules.sys.dao.SysConfigDao;
import com.wedu.modules.sys.dao.SysTestDao;
import com.wedu.modules.sys.entity.SysConfigEntity;
import com.wedu.modules.sys.entity.SysTest;
import com.wedu.modules.sys.redis.SysConfigRedis;
import com.wedu.modules.sys.service.SysConfigService;
import com.wedu.modules.sys.service.SysTestService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

@Service("sysTestService")
public class SysTestServiceImpl extends ServiceImpl<SysTestDao,SysTest> implements SysTestService {

    //分页工具类，查询没被删除的数据
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String) params.get("name");
        IPage<SysTest> page = this.page(
                new Query<SysTest>().getPage(params),
                new QueryWrapper<SysTest>()
                .like(StringUtils.isNotBlank(name),"name",name)
                .eq("deleted",0)
                .orderByDesc("create_time")
        );
        return new PageUtils(page);
    }

    //增加数据
    @Override
    public void saveConfig(SysTest sysTest) {
        this.save(sysTest);
    }

    //删除数据
    @Override
    public void deleteBatch(Long[] ids) {
        this.removeByIds(Arrays.asList(ids));
    }

    //修改数据
    @Override
    public void update(SysTest sysTest) {
        this.updateById(sysTest);
    }

}
